package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.XyEventStatus;
import com.ruoyi.system.service.IXyEventStatusService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件状态Controller
 *
 * @author lxm
 * @date 2024-04-20
 */
@RestController
@RequestMapping("/status/status")
public class XyEventStatusController extends BaseController {
    @Autowired
    private IXyEventStatusService xyEventStatusService;

    /**
     * 查询事件状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:status:list')")
    @GetMapping("/list")
    public TableDataInfo list(XyEventStatus xyEventStatus) {
        startPage();
        List<XyEventStatus> list = xyEventStatusService.selectXyEventStatusList(xyEventStatus);
        return getDataTable(list);
    }

    /**
     * 导出事件状态列表
     */
    @PreAuthorize("@ss.hasPermi('system:status:export')")
    @Log(title = "事件状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyEventStatus xyEventStatus) {
        List<XyEventStatus> list = xyEventStatusService.selectXyEventStatusList(xyEventStatus);
        ExcelUtil<XyEventStatus> util = new ExcelUtil<XyEventStatus>(XyEventStatus.class);
        util.exportExcel(response, list, "事件状态数据");
    }

    /**
     * 获取事件状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:status:query')")
    @GetMapping(value = "/{objectRrn}")
    public AjaxResult getInfo(@PathVariable("objectRrn") Long objectRrn) {
        return success(xyEventStatusService.selectXyEventStatusByObjectRrn(objectRrn));
    }

    /**
     * 新增事件状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:add')")
    @Log(title = "事件状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyEventStatus xyEventStatus) {
        return toAjax(xyEventStatusService.insertXyEventStatus(xyEventStatus));
    }

    /**
     * 修改事件状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:edit')")
    @Log(title = "事件状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyEventStatus xyEventStatus) {
        return toAjax(xyEventStatusService.updateXyEventStatus(xyEventStatus));
    }

    /**
     * 删除事件状态
     */
    @PreAuthorize("@ss.hasPermi('system:status:remove')")
    @Log(title = "事件状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objectRrns}")
    public AjaxResult remove(@PathVariable Long[] objectRrns) {
        return toAjax(xyEventStatusService.deleteXyEventStatusByObjectRrns(objectRrns));
    }
}
